package com.newbee.sustainability.web.config;

import com.newbee.sustainability.web.service.IUserBusinessFegnCilent;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Description：用户服务Feign client factory
 * Date：2019/1/18
 * Time：16:12
 *
 * @author Likailun
 */
@Component
public class UserBusinessFeignClientFallbackFactory implements FallbackFactory<IUserBusinessFegnCilent> {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserBusinessFeignClientFallbackFactory.class);

    @Override
    public IUserBusinessFegnCilent create(Throwable cause) {
        LOGGER.error("fallback; reason was: {}", cause.getMessage());
        return new IUserBusinessFegnCilent() {
            @Override
            public String info() {
                return "fallback; reason was: " + cause.getMessage();
            }

            @Override
            public String save(Map<String, String> user) {
                return "fallback; reason was: " + cause.getMessage();
            }

            @Override
            public String getUser(String id) {
                return "fallback; reason was: " + cause.getMessage();
            }
        };
    }
}
